﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class gonggaoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        Button btnAdd;
        CustomGridView CustomGridList1;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            if (base.Page.Request["action"] != null && base.Page.Request["action"].ToString() == "del" && base.Page.Request["id"] != null)
            {
                bool del = _EluZSDataProvider.DeleteXmByID("zs_gonggao", "id", base.Page.Request["id"]);
                if (del) { base.Page.Response.Redirect("gonggao.aspx"); }
            }
            if (!base.Page.IsPostBack)
            {
                Bind();
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
                if (Page.Request["ID"] != null && Page.Request["action"].ToString() == "edit")
            {
                    string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}');</script>",
                        base.Page.Request["ID"].Trim(), base.Page.Request["ID"].Trim(), base.Page.Request["ID"].Trim());
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }
        
        protected void Bind()
        {
            CustomGridList1.RowDataBound += new GridViewRowEventHandler(CustomGridList1_RowDataBound);
            DataTable dt = _EluZSDataProvider.GetGongGao();
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID" };
            CustomGridList1.DataBind();
        }

        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected void CustomGridList1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                DataRowView dr = (DataRowView)e.Row.DataItem;
                if (dr != null)
                {
                    Label delgonggao = (Label)e.Row.FindControl("delgonggao");
                    if (_EluZSDataProvider.IsNetZSAdmin(userid) || _EluZSDataProvider.IsZSAdmin(userid))
                    {
                        delgonggao.Visible = true;
                    }
                }
            }
        }

    }
}


